#!/usr/bin/node
const log = console.log,
      arg = process.argv[2];


//log(argv);argv是你运行代码的参数数组
////例如，你运行node 02-calc.js
//agvv[0]就是node的地址
//argv[1]就是02-calc.js的地址
//运行 node 02-calc.js 2+3
//5

if(typeof(arg) === 'undefined' ||
    arg === '--help' ||
    arg === '-h') {
  help();
} else {
  calc();
}

function help() {
  const msg = '' 
    + 'usage: cmd-name [OPTION] [expression]\n'
    + 'evaluate the expression.\n'
    + '\n'
    + 'Mandatory arguments to long options are mandatory for short options too.\n'
    + '  -h, --help output help information and exit\n';

  log(msg);
}

function calc() {
  try {
    log(`${arg} = ${eval(arg)}`);
  } catch (e) {
    log('非法表达式');
    // log(e.message);	
  }
}


